package com.naiterui.ehp.bs.cms.modules.sys.entity;

import com.baomidou.mybatisplus.annotation.SqlCondition;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.naiterui.ehp.bs.cms.common.entity.BaseEntity;
import com.naiterui.ehp.bs.cms.common.json.Dict;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 系统用户
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("user")
public class User extends BaseEntity implements Serializable {

  private static final long serialVersionUID = -3974284141753009763L;

  /**
   * 用户名
   */
  @TableField(condition = SqlCondition.LIKE)
  @NotBlank(message = "用户名不能为空")
  private String username;
  /**
   * 用户真实姓名
   */
  @NotBlank(message = "用户真实姓名不能为空")
  private String name;

  /**
   * 密码
   */
  @Pattern(regexp = "^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[^A-Za-z0-9]))(?=^[^\\u4e00-\\u9fa5]{0,}$).{8,20}$", message = "密码过于简单有被盗风险，请保证密码大于8位，并且由大小写字母、数字，特殊符号组成")
  @JsonInclude(JsonInclude.Include.NON_EMPTY)
  private String password;

  /**
   * 邮箱
   */
  @NotBlank(message = "邮箱不能为空")
  @Email(message = "邮箱格式不正确")
  private String email;

  /**
   * 手机号
   */
  @TableField(condition = SqlCondition.EQUAL)
  @NotBlank(message = "手机号不能为空")
  @Pattern(regexp = "^(1[0-9])\\d{9}$", message = "手机号格式不正确")
  private String mobile;

  /**
   * 状态 0：禁用 1：正常
   */
  @Dict(type = "system_status")
  @NotNull(message = "账号状态不能为null")
  private Integer status;

  /**
   * 角色ID列表
   */
  @TableField(exist = false)
  private List<Long> roleIdList;

  /**
   * 部门ID
   */
  @NotNull(message = "部门不能为空")
  private Long deptId;

  /**
   * 部门名称
   */
  @TableField(exist = false)
  private String deptName;

  @JsonIgnore
  @TableLogic
  private Integer delFlag;

  @JsonIgnore
  private Date lastPasswordResetDate;

  @TableField(exist = false)
  private List<Role> roles;

  @TableField(exist = false)
  private Set<String> permissions;

  public User() {
  }

}
